//ajax的进一步封装
function ajax(type, url, str, callback1, callback2) {
    str == undefined && (str = "");
    $.ajax({
        type: type + "",
        url: url + "",
        data: str,
        dataType: "json",
        success: function (data) {
            !(callback1 == undefined) && callback1(data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            !(callback2 == undefined) && callback2();
            // console.log(XMLHttpRequest);
            console.log(errorThrown);
            console.log(textStatus);
            console.log(XMLHttpRequest.status);
            console.log(XMLHttpRequest.readyState);
            console.log(XMLHttpRequest.responseText);
        }
    });
}

//创建数组删除制定项的方法！该方法两个参数：1.指定的数组 2.删除的内容
function removeByValue(arr, val) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] === val) {
            if (arr[i - 1] && (arr[i - 1] === " and " || arr[i - 1] === " ＜ " || arr[i - 1] === " ＞ " || arr[i - 1] === " = " || arr[i - 1] === " between ")) {
                arr.splice(i - 1, 2);
                break;
            } else {
                arr.splice(i, 1);
            }

        }
    }
}

function alertModel(title, body) {
    if (!title) {
        title = '温馨提示';
    }
    if (!body) {
        body = '出错了，再来一次！';
    }
    $.alert({
        title: title,
        body: body,
        transition: true
    });
}

//检查返回数据是否是undefined
function checkUndefined(data) {
    return (data === undefined || data === null) ? "" : data;

};


function checkRangeInput(value) {
    String(value);
    if (value.indexOf("+") !== -1 || value.indexOf("-") !== -1) {
        return false;
    } else if (value.indexOf(".") !== -1) {
        var map = {};
        for (var i = 0; i < value.length; i++) {
            var s = value[i];
            var r = map[s];
            if (r) {
                map[s] += 1;
            } else {
                map[s] = 1;
            }
        }
        JSON.stringify(map);
        if (map["."] !== 1) {
            return false;
        } else {
            return true;
        }

    } else {
        return true
    }
}

//退出跳转
function aClick() {
    //跳转
    window.location.pathname = "/manage/auth/logout";
    //清除缓存
    sessionStorage.clear();
    localStorage.clear();
};


//当数据为空的时候，报错导致程序无法继续走下去，这里是容错方法⬇️
//当用传参数，注意参数需要加引号；
function CheckTypeErr(data) {
    var state = 0;
    try {
        eval(data)
    } catch (err) {
        state = 1;
    } finally {
        if (state) {
            return "";
        } else {
            return eval(data);

        }
    }
}

$(function () {
    $.each($(".numberStrict"), function (k, v) {
        $(v).bind('blur', function () {
            if (isNaN($(v).val()) || $(v).val() === "") {
                $(v).val("");
            }
        })
    });
});


//confirm 弹窗  start
function confirmModel(title, body, okBtn, cancelBtn, okHidden) {
    if (!title) {
        title = '温馨提示';
    }
    if (!body) {
        body = '确定要删除吗？';
    }
    if (!okBtn) {
        okBtn = '确定';
    }
    if (!cancelBtn) {
        cancelBtn = '取消';
    }
    $.confirm({
        title: title,
        body: body,
        okBtn: okBtn,
        cancelBtn: cancelBtn,
        transition: true,
        okHidden: function () {
            okHidden();
        }
    });
} //confirm 弹窗  end

//alert 弹窗  start
function alertModel(title, body) {
    if (!title) {
        title = '温馨提示';
    }
    if (!body) {
        body = '出错了，再来一次！';
    }
    $.alert({
        title: title,
        body: body,
        transition: true
    });
} //alert 弹窗  end


//检查最大值最小值⬇️
function checkMInMax(val, min, max, bit) {
    if (val == "") {
        return val;
    }
    else if (Number(val) <= Number(min)) {
        return min
    } else if (Number(val) >= max) {
        return max
    } else if (val.indexOf(".") >= 0) {
        if (isNaN(val)) {
            return ""
        } else {
            return Number(val).toFixed(bit)
        }
    } else {
        return val;
    }
}

// 检查日期时间的大小⬇
function compareTime(startDate, endDate) {
    if (startDate.length > 0 && endDate.length > 0) {
        var startDateTemp = startDate.split(" ");
        var endDateTemp = endDate.split(" ");

        var arrStartDate = startDateTemp[0].split("-");
        var arrEndDate = endDateTemp[0].split("-");

        var arrStartTime = startDateTemp[1].split(":");
        var arrEndTime = endDateTemp[1].split(":");

        var allStartDate = new Date(arrStartDate[0], arrStartDate[1], arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
        var allEndDate = new Date(arrEndDate[0], arrEndDate[1], arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);

        if (allStartDate.getTime() >= allEndDate.getTime()) {
            // alert("startTime不能大于endTime，不能通过");
            return false;
        } else {
            // alert("startTime小于endTime，所以通过了");
            return true;
        }
    } else {
        // alert("时间不能为空");
        return false;
    }
}

// 血糖图普方法封装⬇
//chart2-1a 最新血糖图谱 Start todo 1
var chart2_1a = function (data, minTime, maxTime, username, referList, medicalInfo1, medicalInfo2, diet, motion, width) {


    // minTime -= 72000000;
    // minTime -= 72000000;
    minTime -= 108000000;
    maxTime += 108000000;
    Highcharts.setOptions({
        lang: {
            months: ['1月', '2月', '3月', '4月', '5月', '6月', '7月',
                '8月', '9月', '10月', '11月', '12月'],
            shortMonths: ['1月', '2月', '3月', '4月', '5月', '6月', '7月',
                '8月', '9月', '10月', '11月', '12月'],
            weekdays: ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
        }
    });
    $('#chart2-1a').highcharts({
        chart: {
            renderTo: 'container',
            type: 'line',
            zoomType: 'x',
            spacingTop: 0,
            spacingRight: 100,
            spacingBottom: 0,
            spacingLeft: 0,
            // width: $('div[id*="highcharts"]').width(),
            // Width:width,
            height: 400
        },
        credits: {
            enabled: false
        },
        global: {
            useUTC: true
        },
        title: {
            text: username + '：最新血糖数据'
        },
        xAxis: {
            type: 'datetime',//标志时间
            min: minTime,
            max: maxTime+86400000,
            dateTimeLabelFormats: {
                second: '%Y-%m-%d<br/>%H:%M:%S',
                minute: '%H:%M',
                hour: '%H:%M',
                day: '%Y<br/>%m-%d',
                week: '%Y<br/>%m-%d',
                month: '%Y-%m',
                year: '%Y'
            },
            // categories: ['00:00<br>2016-05-21', '08:00', '16:00', '00:00<br>2016-05-22', '08:00', '16:00', '00:00<br>2016-05-23', '08:00', '16:00', '00:00<br>2016-05-24', '08:00', '16:00', '00:00<br>2016-05-25', '08:00', '16:00', '00:00<br>2016-05-26', '08:00', '16:00', '00:00<br>2016-05-27', '08:00', '16:00']
        },
        yAxis: {
            min: 0,
            max: 25,
            showEmpty: false,
            title: {
                text: 'mmol/L'//纵轴标题
            },
            lineWidth: 1,
            //颜色划分区域
            plotBands: [{ // 高血糖
                from: 11.1,
                to: 25,
                color: 'rgba(168, 211, 236, 1)'
            }, { // 正常
                from: 7.8,
                to: 11.1,
                color: 'rgba(0, 0, 0, 0)'
            }, { // 正常
                from: 7.0,
                to: 7.8,
                color: 'rgba(0, 0, 0, 0)'
            }, { // 低血糖
                from: 5.6,
                to: 7.0,
                color: 'rgba(254, 246, 202,1)'
            }, { // 低血糖
                from: 3.9,
                to: 5.6,
                color: 'rgba(255, 238, 165, 1)'
            }, { // 低血糖
                from: 1.7,
                to: 3.9,
                color: 'rgba(255, 211, 145, 1)'
            }, { // 低血糖
                from: 0,
                to: 1.7,
                color: 'rgba(254, 177, 121, 1)'
            }]
        },


        tooltip: {
            enabled: true,
            dateTimeLabelFormats: {
                millisecond: '%A, %b %e, %H:%M:%S.%L',
                second: '%A, %b %e, %H:%M:%S',
                minute: '%A, %b %e, %H:%M',
                hour: '%A, %b %e, %H:%M',
                day: '%A, %b %e, %Y',
                week: 'Week from %A, %b %e, %Y',
                month: '%B %Y',
                year: '%Y'
            },
            headerFormat: '<span style="font-size: 12px">{point.key}</span><br/>',
            pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b>mmol/L<br/>',
            xDateFormat: '%Y-%m-%d %H:%M'
        },
        legend: {
            layout: 'horizontal',
            align: 'center',
            verticalAlign: 'bottom',
            borderWidth: 1,
            borderColor: '#CCC'
        },
        plotOptions: {
            series: {
                marker: {
                    radius: 5, //曲线点半径，默认是4
                    symbol: 'circle' //曲线点类型："circle", "square", "diamond", "triangle","triangle-down"，默认是"circle"
                },
                events: {
                    click: function (e) {
                        if (e.point.id) {
                            $('#xt_id').val(e.point.id);
                            $('#xt_time').val(e.point.x);
                            $('#xt_value').val(e.point.y);
                        }
                    }
                }
            },
            scatter: {
                tooltip: {
                    headerFormat: '<span style="font-size: 12px">{point.key}</span><br/>',
                    pointFormat: '<span style="color:{series.color}">{series.name}<br/><br/></span><b>{point.attr}</b><br/>',
                    xDateFormat: '%Y-%m-%d %H:%M'
                }
            }
        },


        series: [{//血糖数据
            name: '血糖值',
            data: data,
            marker: {
                enabled: false
            },
            states: {
                hover: {lineWidth: 2}
            },
            color: '#4572A7',
            lineWidth: 1.5
        }, {
            type: 'scatter',
            name: '参比血糖',
            color: '#FF4949',
            marker: {radius: 4, symbol: 'circle'},
            data: referList
        }, {
            type: 'scatter',
            name: '注射胰岛素',
            color: '#F07BDD',
            marker: {radius: 4, symbol: 'triangle'},
            data: medicalInfo1
        }, {
            type: 'scatter',
            name: '用药',
            color: '#2ED7B8',
            marker: {radius: 4, symbol: 'triangle'},
            data: medicalInfo2
        }, {
            type: 'scatter',
            name: '运动',
            color: '#F4B64C',
            marker: {radius: 4, symbol: 'triangle-down'},
            data: motion
        }, {
            type: 'scatter',
            name: '饮食',
            color: '#B699EB',
            marker: {radius: 4, symbol: 'diamond'},
            data: diet
        }]

//    series: [{
//      type: 'area',
//      name: '血糖值',
//      color:'#b2ffd0',
//      data: [ 1.9, 2.5, 5.3, 12.3, 7.0, 6.9, 9.5, 14.5, 9.6, 12, 25, 14.5, 18.2, 21.5, 21.2, 18.2, 21.5, 21.2, 2.5, 5.3, 12.3]
//    }, {
//      type: 'scatter',
//      name: '参比血糖',
//      color: '#3d4aef',
//      data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 21.2, 2.5, 5.3, 12.3, 1.9, 9.6, 12, 25, 14.5, 18.2, 21.5, 21.2, 2.5, 5.3, 12.3]
//    }, {
//      type: 'scatter',
//      name: '注射胰岛素',
//      color: '#ff7676',
//      data: [-10, null, -10, -10, -10, null, null, null, null, -10, -10, -10, null, -10, -10, null, -10, -10, null, null, -10]
//    }, {
//      type: 'scatter',
//      name: '用药',
//      color: '#7de953',
//      data: [-20, null, -20, null, null, null, -20, -20, -20, null, -20, -20, -20, -20, null, null, -20, -20, null, null, -20]
//    }, {
//      type: 'scatter',
//      name: '运动',
//      color: '#7dfcf8',
//      data: [-30, null, -30, null, null, null, -30, -30, -30, null, -30, null, -30, -30, null, -30, -30, -30, null, null, -30]
//    }, {
//      type: 'scatter',
//      name: '饮食',
//      color: '#ef3de9',
//      data: [-40, null, -40, null, -40, null, -40, -40, -40, -40, null, null, -40, -40, null, null, -40, -40, null, null, -40]
//    }]
    });
};
//chart2-1a 最新血糖图谱 End


//chart2-2b 日间同比图谱谱 Start todo 2
var chart2_2b = function (data, width) {
    // console.log(data);
    var mintime = 0;
    var maxtime = 24 * 60 * 60 * 1000;
    $('#chart2-2b').highcharts({
        chart: {
            renderTo: 'container',
            type: 'spline',
            spacingTop: 10,
            spacingRight: 100,
            spacingBottom: 0,
            spacingLeft: 0,
            // width:width
        },
        exporting: {
            enabled: false //用来设置是否显示‘打印’,'导出'等功能按钮，不设置时默认为显示
        },
        global: {
            useUTC: true
        },
        credits: {
            enabled: false
        },
        plotOptions: {
            scatter: {
                tooltip: {
                    headerFormat: "<span style='font-size: 12px'>{point.key}</span><br/>",
                    pointFormat: "<span style='color:{series.color}'>{series.name}:</span><b>{point.attr}</b><br/>",
                    xDateFormat: '%Y-%m-%d %H:%M'
                }
            }
        },
        tooltip: {
            enabled: true,
            dateTimeLabelFormats: {
                millisecond: '%A, %b %e, %H:%M:%S.%L',
                second: '%A, %b %e, %H:%M:%S',
                minute: '%A, %b %e, %H:%M',
                hour: '%A, %b %e, %H:%M',
                day: '%A, %b %e, %Y',
                week: 'Week from %A, %b %e, %Y',
                month: '%B %Y',
                year: '%Y'
            },
            followPointer: true,
            followTouchMove: true,
            headerFormat: "<span style='font-size: 12px'>{series.name}{point.key}</span><br/>",
            pointFormat: "<b>{point.y}</b>mmol/L<br/>",
            xDateFormat: ' %H:%M'
        },

        title: {
            text: ''
        },
        xAxis: {
            type: 'datetime',
            mn: mintime,
            max: maxtime - 1,
            dateTimeLabelFormats: {
                second: '%Y-%m-%d<br/>%H:%M:%S',
                minute: '%H:%M',
                hour: '%H:%M',
                // day: '%Y<br/>%m-%d',
                day: '%H:%M',
                week: '%Y<br/>%m-%d',
                month: '%Y-%m',
                year: '%Y'
            }
//      categories: ['01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00']
        },
        yAxis: {
            min: 0,
            max: 25,
            showEmpty: false,
            title: {
                text: 'mmol/L'//纵轴标题
            },
            lineWidth: 1,
            //颜色划分区域
            plotBands: [
                { // 高血糖
                    from: 11.1,
                    to: 25,
                    color: 'rgba(168, 211, 236, 1)'
                },
                { // 正常
                    from: 7.8,
                    to: 11.1,
                    color: 'rgba(0, 0, 0, 0)'
                },
                { // 正常
                    from: 7.0,
                    to: 7.8,
                    color: 'rgba(0, 0, 0, 0)'
                },
                { // 低血糖
                    from: 5.6,
                    to: 7.0,
                    color: 'rgba(254, 246, 202,1)'
                },
                { // 低血糖
                    from: 3.9,
                    to: 5.6,
                    color: 'rgba(255, 238, 165, 1)'
                },
                { // 低血糖
                    from: 1.7,
                    to: 3.9,
                    color: 'rgba(255, 211, 145, 1)'
                },
                { // 低血糖
                    from: 0,
                    to: 1.7,
                    color: 'rgba(254, 177, 121, 1)'
                }
            ]
        },
        series: data
    });
};
//chart2-2b 日间同比图谱 End


//chart2-2c 高低血糖百分比 Start todo 3
var chart2_2c = function (data1, data2, data3) {
    data3 = Number(data3);
    $('#chart2-2c').highcharts({
        chart: {
            type: 'pie',
            options3d: {
                enabled: true,
                alpha: 45
            }
        },
        credits: {
            enabled: false
        },
        title: {
            text: ''
        },

        legend: {
            layout: 'horizontal',
            align: 'center',
            verticalAlign: 'bottom',
            borderWidth: 1,
            borderColor: '#CCC',
            labelFormatter: function () {
                return this.name + '(' + this.percentage.toFixed(1) + '%)';
            }
        },

        tooltip: {
            pointFormat: '{point.percentage:.1f}%'
        },
        plotOptions: {
            pie: {
                colors: ['#ff5c5c', '#fcc245', '#50d879'],
                innerSize: 100,
                depth: 45,
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %'
                },
                showInLegend: true,
                point: {
                    events: {
                        legendItemClick: function (e) {
                            return false; //阻止点击图例隐藏
                        }
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: '高低血糖百分比',
            data: [
                ['高血糖（血糖值&gt;=7.8）', parseFloat(data2)],
                ['低血糖（血糖值&lt;=3.9）', parseFloat(data1)],
                ['正常血糖', data3]
            ]
        }]
    });
};
//chart2-2c 高低血糖百分比 End


//chart2-2d 饮食事件同比图谱 Start todo 4
var chart2_2d = function (data) {
    var mintime = 0;
    var maxtime = 3 * 60 * 60 * 1000;
    // console.log(data);
    $('#chart2-2d').highcharts({
        chart: {
            renderTo: 'container',
            type: 'spline'
        },
        exporting: {
            enabled: false //用来设置是否显示‘打印’,'导出'等功能按钮，不设置时默认为显示
        },
        global: {
            useUTC: true
        },
        credits: {
            enabled: false
        },
        plotOptions: {
            scatter: {
                tooltip: {
                    headerFormat: "<span style='font-size: 12px'>{point.key}</span><br/>",
                    pointFormat: "<span style='color:{series.color}'>{series.name}:</span><b>{point.attr}</b><br/>",
                    xDateFormat: '%Y-%m-%d %H:%M'
                }
            }
        },
        tooltip: {
            enabled: true,
            dateTimeLabelFormats: {
                millisecond: '%A, %b %e, %H:%M:%S.%L',
                second: '%A, %b %e, %H:%M:%S',
                minute: '%A, %b %e, %H:%M',
                hour: '%A, %b %e, %H:%M',
                day: '%A, %b %e, %Y',
                week: 'Week from %A, %b %e, %Y',
                month: '%B %Y',
                year: '%Y'
            },
            followPointer: true,
            followTouchMove: true,
            headerFormat: "<span style='font-size: 12px'>{series.name}{point.key}</span><br/>",
            pointFormat: "<b>{point.y}</b>mmol/L<br/>",
            xDateFormat: ' %H:%M'
        },

        title: {
            text: ''
        },
        xAxis: {
            type: 'datetime',
            mn: mintime,
            max: maxtime,
            dateTimeLabelFormats: {
                second: '%Y-%m-%d<br/>%H:%M:%S',
                minute: '%H:%M',
                hour: '%H:%M',
                // day: '%Y<br/>%m-%d',
                day: '%H:%M',
                week: '%Y<br/>%m-%d',
                month: '%Y-%m',
                year: '%Y'
            }
//      categories: ['01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00']
        },
        yAxis: {
            min: 0,
            max: 25,
            showEmpty: false,
            title: {
                text: 'mmol/L'//纵轴标题
            },
            lineWidth: 1,
            //颜色划分区域
            plotBands: [
                { // 高血糖
                    from: 11.1,
                    to: 25,
                    color: 'rgba(168, 211, 236, 1)'
                },
                { // 正常
                    from: 7.8,
                    to: 11.1,
                    color: 'rgba(0, 0, 0, 0)'
                },
                { // 正常
                    from: 7.0,
                    to: 7.8,
                    color: 'rgba(0, 0, 0, 0)'
                },
                { // 低血糖
                    from: 5.6,
                    to: 7.0,
                    color: 'rgba(254, 246, 202,1)'
                },
                { // 低血糖
                    from: 3.9,
                    to: 5.6,
                    color: 'rgba(255, 238, 165, 1)'
                },
                { // 低血糖
                    from: 1.7,
                    to: 3.9,
                    color: 'rgba(255, 211, 145, 1)'
                },
                { // 低血糖
                    from: 0,
                    to: 1.7,
                    color: 'rgba(254, 177, 121, 1)'
                }
            ]
        },
        series: data
    });
};
//chart2-2d 饮食事件同比图谱 End

//chart2-2e 胰岛素同比图谱 Start todo 5
var chart2_2e = function (data) {
    var mintime = 0;
    var maxtime = 3 * 60 * 60 * 1000;
    $('#chart2-2e').highcharts({
        chart: {
            renderTo: 'container',
            type: 'spline'
        },
        exporting: {
            enabled: false //用来设置是否显示‘打印’,'导出'等功能按钮，不设置时默认为显示
        },
        global: {
            useUTC: true
        },
        credits: {
            enabled: false
        },
        plotOptions: {
            scatter: {
                tooltip: {
                    headerFormat: "<span style='font-size: 12px'>{point.key}</span><br/>",
                    pointFormat: "<span style='color:{series.color}'>{series.name}:</span><b>{point.attr}</b><br/>",
                    xDateFormat: '%Y-%m-%d %H:%M'
                }
            }
        },
        tooltip: {
            enabled: true,
            dateTimeLabelFormats: {
                millisecond: '%A, %b %e, %H:%M:%S.%L',
                second: '%A, %b %e, %H:%M:%S',
                minute: '%A, %b %e, %H:%M',
                hour: '%A, %b %e, %H:%M',
                day: '%A, %b %e, %Y',
                week: 'Week from %A, %b %e, %Y',
                month: '%B %Y',
                year: '%Y'
            },
            followPointer: true,
            followTouchMove: true,
            headerFormat: "<span style='font-size: 12px'>{series.name}{point.key}</span><br/>",
            pointFormat: "<b>{point.y}</b>mmol/L<br/>",
            xDateFormat: ' %H:%M'
        },

        title: {
            text: ''
        },
        xAxis: {
            type: 'datetime',
            mn: mintime,
            max: maxtime,
            dateTimeLabelFormats: {
                second: '%Y-%m-%d<br/>%H:%M:%S',
                minute: '%H:%M',
                hour: '%H:%M',
                // day: '%Y<br/>%m-%d',
                day: '%H:%M',
                week: '%Y<br/>%m-%d',
                month: '%Y-%m',
                year: '%Y'
            }
//	      categories: ['01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00', '23:00', '24:00']
        },
        yAxis: {
            min: 0,
            max: 25,
            showEmpty: false,
            title: {
                text: 'mmol/L'//纵轴标题
            },
            lineWidth: 1,
            //颜色划分区域
            plotBands: [
                { // 高血糖
                    from: 11.1,
                    to: 25,
                    color: 'rgba(168, 211, 236, 1)'
                },
                { // 正常
                    from: 7.8,
                    to: 11.1,
                    color: 'rgba(0, 0, 0, 0)'
                },
                { // 正常
                    from: 7.0,
                    to: 7.8,
                    color: 'rgba(0, 0, 0, 0)'
                },
                { // 低血糖
                    from: 5.6,
                    to: 7.0,
                    color: 'rgba(254, 246, 202,1)'
                },
                { // 低血糖
                    from: 3.9,
                    to: 5.6,
                    color: 'rgba(255, 238, 165, 1)'
                },
                { // 低血糖
                    from: 1.7,
                    to: 3.9,
                    color: 'rgba(255, 211, 145, 1)'
                },
                { // 低血糖
                    from: 0,
                    to: 1.7,
                    color: 'rgba(254, 177, 121, 1)'
                }
            ]
        },
        series: data
    });
};
//chart2-2e 胰岛素同比图谱 End


//血糖图谱公用方法⬇
function chartsCallBack(data) {
    if (data.code == 10000) {
        dataThree = data.data;
        DBGChartShow(dataThree)
    }
}

function chartsCallBack(data) {
    if (data.code == 10000) {
        dataThree = data.data;
        DBGChartShow(dataThree)
    }
}

var dataAjaxState = false;
var dataAjaxState1 = false;
var dataAjaxState2 = false;

function chartsCallBack1(data) {
    if (data.code == 10000) {
        DBGChartShow1(data.data)
    }
}

function chartsCallBack2(data) {
    if (data.code == 10000) {
        DBGChartShow2(data.data)
    }
}

function DBGChartShow(dataThree) {
    setTimeout(function () {
        // if (!dataAjaxState) {
        //连续血糖调用⬇️
        var uName = "";
        if (dataThree.user) {
            uName = dataThree.user.name
        } else {
            uName = ""
        }
        chart2_1a(dataThree.glucose, dataThree.min, dataThree.max, uName, dataThree.referGlucose, dataThree.medicalInfo1, dataThree.medicalInfo2, dataThree.diet, dataThree.motion);
        //日间同比血糖调用⬇️
        chart2_2b(dataThree.dateGlucose);
        //高低血糖百分比⬇️
        chart2_2c(dataThree.minPercentage, dataThree.maxPercentage, dataThree.normalPercentage);

        // }
        dataAjaxState = true;

    }, 10);
}

function DBGChartShow1(data) {
    setTimeout(function () {
        if (!dataAjaxState1) {
            //饮食事件同比图谱⬇️
            chart2_2d(data);
        }
        dataAjaxState1 = true;

    }, 10);
}

function DBGChartShow2(data) {
    setTimeout(function () {
        if (!dataAjaxState2) {
            //胰岛素同比图谱⬇️
            chart2_2e(data);
        }
        dataAjaxState2 = true;

    }, 10);
}


//获取url中"?"符后的字串,返回对象⬇️
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

// 对Date的扩展，将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}